package com.yk.web.controller;

import java.util.List;

import com.yk.common.utils.DateUtils;
import com.yk.system.domain.SysIndexPicture;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.points.domain.PointsGoods;
import com.yk.points.service.IPointsGoodsService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 商品积分Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/points/pointsGoods")
public class PointsGoodsController extends BaseController
{
    private String prefix = "points/pointsGoods";

    @Autowired
    private IPointsGoodsService pointsGoodsService;

    @RequiresPermissions("points:pointsGoods:view")
    @GetMapping()
    public String pointsGoods()
    {
        return prefix + "/pointsGoods";
    }

    /**
     * 查询商品积分列表
     */
    @RequiresPermissions("points:pointsGoods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PointsGoods pointsGoods)
    {
        startPage();
        List<PointsGoods> list = pointsGoodsService.selectPointsGoodsList(pointsGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品积分列表
     */
    @RequiresPermissions("points:pointsGoods:export")
    @Log(title = "商品积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PointsGoods pointsGoods)
    {
        List<PointsGoods> list = pointsGoodsService.selectPointsGoodsList(pointsGoods);
        ExcelUtil<PointsGoods> util = new ExcelUtil<PointsGoods>(PointsGoods.class);
        return util.exportExcel(list, "商品积分数据");
    }

    /**
     * 新增商品积分
     */
    @RequiresPermissions("points:pointsGoods:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品积分
     */
    @RequiresPermissions("points:pointsGoods:add")
    @Log(title = "商品积分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PointsGoods pointsGoods)
    {
        return toAjax(pointsGoodsService.insertPointsGoods(pointsGoods));
    }

    /**
     * 修改商品积分
     */
    @RequiresPermissions("points:pointsGoods:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PointsGoods pointsGoods = pointsGoodsService.selectPointsGoodsById(id);
        mmap.put("pointsGoods", pointsGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品积分
     */
    @RequiresPermissions("points:pointsGoods:edit")
    @Log(title = "商品积分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PointsGoods pointsGoods)
    {
        return toAjax(pointsGoodsService.updatePointsGoods(pointsGoods));
    }

    @RequiresPermissions("points:pointsGoods:changeStatus")
    @Log(title = "修改积分商品上架状态", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(PointsGoods pointsGoods)
    {
        if ("0".equals(pointsGoods.getStatus()))
            pointsGoods.setShelveTime(DateUtils.getNowDate());

        return toAjax(pointsGoodsService.updatePointsGoods(pointsGoods));
    }
    /**
     * 删除商品积分
     */
    @RequiresPermissions("points:pointsGoods:remove")
    @Log(title = "商品积分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pointsGoodsService.deletePointsGoodsByIds(ids));
    }
}
